package com.xc.stock.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.core.env.Environment;
import org.springframework.web.context.ContextLoader;

/**
 * 环境变量
 * 
 * @author xlfd
 * @email xlfd@gmail.com
 * @version 1.0
 * @created Jun 2, 2020 10:00:59 AM
 */
@Configuration
@PropertySources({
	@PropertySource("classpath:stock2guo.properties"),
})
public class Env {
	@Autowired
	Environment environment;
	@Value("${enable.scheduled:true}")
	boolean enabledScheduled;


	static Env env;

	public static Env of() {
		if (env == null) {
			ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
			env = ctx.getBean(Env.class);
		}

		return env;
	}

	public boolean enabledScheduled() {
		return enabledScheduled;
	}
	
	public String domain() {
		return environment.getProperty("domain");
	}
	
	public String springProfilesActive() {
		return environment.getProperty("spring.profiles.active");
	}
	
	public boolean isProd() {
		return "prod".equals(springProfilesActive());
	}

	public Environment environment() {
		return environment;
	}
}